//
//  CSSStatus.swift
//  weibo28
//
//  Created by chushushan on 16/5/14.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
//微博数据模型
class CSSStatus: NSObject {

    //发微博事件
    var created_at: String?
    //微博ID
    var id: Int64 = 0
    //微博内容
    var text: String?
    //微博来源
    var source: String?
    //用户模型
    var user: CSSUser?
    
    //转发微博
    var retweeted_status: CSSStatus?
    //转发数
    var reposts_count: Int = 0
    //评论数
    var comments_count: Int = 0
    //表态数
    var attitudes_count: Int = 0
    
    //配图信息
    var pic_urls: [CSSStatusPictureInfo]?
    
    
    
   //kvc构造函数
     init(dic: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dic)
        
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
        
            guard let dic = value as? [String: AnyObject] else {
            return
            }
            
            user = CSSUser(dic: dic)
        } else if key == "retweeted_status" {
        
            guard let dic = value as? [String: AnyObject] else {
            
                return
            }
            //自定义字典转模型
            retweeted_status = CSSStatus(dic: dic)
            
        } else if key == "pic_urls" {
        
            guard let dicArray = value as? [[String: AnyObject]] else {
            return
            }
            
            //创建空数组
            var tempArray = [CSSStatusPictureInfo]()
            //遍历数组
            for dic in dicArray {
                let picInfo = CSSStatusPictureInfo(dic: dic)
                
                tempArray.append(picInfo)
            }
         pic_urls = tempArray
        }
        
        else {
            
            super.setValue(value, forKey: key)
        }
        
    }

    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {

    }
    
  
}









